#ifndef __TEXT_COMPARER_H__
#define __TEXT_COMPARER_H__

#include <iostream>
#include <vector>
#include <list>
#include "..\Common\ISingleton.h"
#include "TextDiff.h"

namespace TextDiffAlgo
{
	template<class T>
	class Vector2D {
	public:
		std::vector<std::vector<T>>		vv2;
		void							resize(int x, int y)
		{
			vv2.resize(x);
			for (int i = 0; i < x; i++) {
				vv2[i].resize(y);
			}
		}
	};

	class tPoint {
	private:
		int								x;
		int								y;

	public:
										tPoint(int in_x, int in_y): x(in_x), y(in_y) { }
		int								getX() { return x; }
		void							setX(int in_x) { x = in_x; }
		int								getY() { return y; }
		void							setY(int in_y) { y = in_y; }

		bool							operator==(const tPoint& b) { return (b.x == x && b.y == y); }
		bool							operator!=(const tPoint& b) { return !(*this == b); }

		std::string						toString();
	};

	class TextComparer : public ISingleton {
		DECLARE_SINGLETON(TextComparer);

	protected:
		virtual void					InitialInstance() { }
		virtual void					DisposeInstance() { }

	public:
		std::list<TextDiff>				compare(std::string source, std::string compareTo);

	private:
		std::list<TextDiff>				calcDiffs(tPoint startPoint, Vector2D<bool> barr, Vector2D<int> miarr, Vector2D<int> diarr);
		tPoint							getNext(tPoint p, Vector2D<int> miarr, Vector2D<int> diarr, Vector2D<bool> barr);
		Vector2D<bool>					getCompareBoolArray(std::string source, std::string compareTo);
		Vector2D<int>					getSetpPathArr(Vector2D<bool> barr);
		Vector2D<int>					getMinSetpArr(Vector2D<int> miarr, Vector2D<bool> barr);
		int								getV(Vector2D<int> arr, int i, int j);
	};
}

#endif ///> end of __TEXT_COMPARER_H__